package com.welab.pandahelper;

import android.content.Context;
import android.util.Log;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.google.gson.Gson;
import com.welab.pandahelper.bean.MyResponse;
import com.welab.pandahelper.http.OkHttpHelper;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import okhttp3.Response;

import static org.junit.Assert.*;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        assertEquals("com.welab.pandahelper", appContext.getPackageName());
    }


    @Test
    public void giftList(){
        String url = "https://www.oextool.com/api/orderList_no.do?giftId=&pageIndex=1&apptoken=" + "OTY2RTFDQzJGQjEyMEE2NDVEMzJCQ0U0MjYyQzJFRjY0MDc0MUI3QTA4NkU0M0ZDQ0Q2QzdGRTI4Njc3MUQ2MDVDNzRFODZCQkI3MzRFMjYxRTI5MTM5OTQxM0UxRkMz";
        System.out.println("1111111111=========");
        Log.e("eee","1111");
        try {
            Log.e("eee","2222");
            Response response = OkHttpHelper.getOkHttpHelperInstance().get(url);
            Log.e("eee","3333");
            if (response.isSuccessful()){
                Log.e("eee","4444");
                String resultSrt = response.body().string();
                Log.e("eee",resultSrt);
                MyResponse myResponse = new Gson().fromJson(resultSrt,MyResponse.class);
                List<Map<String,String>> giftList = (List<Map<String,String>>) myResponse.getData();
                if(myResponse.getSuccess()){
                    Log.e("eee","success");
                }
                for (Map<String,String> m:giftList
                     ) {
                    Log.e("eee",m.get("giftName"));
                    System.out.println(m.get("giftName"));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}